﻿using System;
using System.Xml.Linq;
using System.Collections.Generic;
using Net.Chirash.Twitter.TwitterDatabase;

namespace Net.Chirash.Twitter.TwitterClient
{
    public static partial class ParseExtends
    {
        //#region Public Properties

        //#region public long ID { get; set; }
        //private long _ID;
        //public long ID
        //{
        //    get { return _ID; }
        //    set { _ID = value; OnPropertyChanged("ID"); }
        //}
        //#endregion

        //#region public string Text { get; set; }
        //private string _Text;
        //public string Text
        //{
        //    get { return _Text; }
        //    set { _Text = value; OnPropertyChanged("Text"); }
        //}
        //#endregion

        //#region public long SenderID { get; set; }
        //private long _SenderID;
        //public long SenderID
        //{
        //    get { return _SenderID; }
        //    set { _SenderID = value; OnPropertyChanged("SenderID"); }
        //}
        //#endregion

        //#region public long RecipientID { get; set; }
        //private long _RecipientID;
        //public long RecipientID
        //{
        //    get { return _RecipientID; }
        //    set { _RecipientID = value; OnPropertyChanged("RecipientID"); }
        //}
        //#endregion

        //#region public DateTime CreatedAt { get; set; }
        //private DateTime _CreatedAt;
        //public DateTime CreatedAt
        //{
        //    get { return _CreatedAt; }
        //    set { _CreatedAt = value; OnPropertyChanged("CreatedAt"); }
        //}
        //#endregion

        //#region public string SenderScreenName { get; set; }
        //private string _SenderScreenName;
        //public string SenderScreenName
        //{
        //    get { return _SenderScreenName; }
        //    set { _SenderScreenName = value; OnPropertyChanged("SenderScreenName"); }
        //}
        //#endregion

        //#region public string RecipientScreenName { get; set; }
        //private string _RecipientScreenName;
        //public string RecipientScreenName
        //{
        //    get { return _RecipientScreenName; }
        //    set { _RecipientScreenName = value; OnPropertyChanged("RecipientScreenName"); }
        //}
        //#endregion

        //#endregion

        #region Public Static Methods

        /// <summary>
        /// Parse DirectMessage XML text for DirectMessage
        /// </summary>
        /// <param name="xml">DirectMessage XML to parse</param>
        /// <returns>DirectMessage</returns>
        public static DirectMessage Parse(this DirectMessage message, string xml)
        {
            XElement element = XElement.Parse(xml);
            //DirectMessage message = new DirectMessage();
            message.DirectMessageID = Convert.ToInt64(element.Element("id").Value);
            message.Text = element.Element("text").Value;
            message.SenderID = Convert.ToInt64(element.Element("sender_id").Value);
            message.RecipientID = Convert.ToInt64(element.Element("recipient_id").Value);
            message.CreatedAt = DateTime.ParseExact(element.Element("created_at").Value, "ddd MMM d HH':'mm':'ss zzz yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo);//
            message.SenderScreenName = element.Element("sender_screen_name").Value;
            message.RecipientScreenName = element.Element("recipient_screen_name").Value;

            message.Sender = new User().Parse(element.Element("sender").ToString());
            message.Recipient = new User().Parse(element.Element("recipient").ToString());
            return message;
        }

        #endregion
    }
}
